package com.hello.system.service.impl;

import java.util.List;
import com.hello.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hello.system.mapper.TreeHoleReadRecordsMapper;
import com.hello.system.domain.TreeHoleReadRecords;
import com.hello.system.service.ITreeHoleReadRecordsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 树洞内容已阅记录Service业务层处理
 * 
 * @author hello
 * @date 2025-05-27
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TreeHoleReadRecordsServiceImpl extends ServiceImpl<TreeHoleReadRecordsMapper, TreeHoleReadRecords> implements ITreeHoleReadRecordsService 
{
    private final TreeHoleReadRecordsMapper treeHoleReadRecordsMapper;

    /**
     * 查询树洞内容已阅记录
     * 
     * @param recordId 树洞内容已阅记录主键
     * @return 树洞内容已阅记录
     */
    @Override
    public TreeHoleReadRecords selectTreeHoleReadRecordsByRecordId(Long recordId)
    {
        return treeHoleReadRecordsMapper.selectTreeHoleReadRecordsByRecordId(recordId);
    }

    /**
     * 查询树洞内容已阅记录列表
     * 
     * @param treeHoleReadRecords 树洞内容已阅记录
     * @return 树洞内容已阅记录
     */
    @Override
    public List<TreeHoleReadRecords> selectTreeHoleReadRecordsList(TreeHoleReadRecords treeHoleReadRecords)
    {
        return treeHoleReadRecordsMapper.selectTreeHoleReadRecordsList(treeHoleReadRecords);
    }

    /**
     * 新增树洞内容已阅记录
     * 
     * @param treeHoleReadRecords 树洞内容已阅记录
     * @return 结果
     */
    @Override
    public int insertTreeHoleReadRecords(TreeHoleReadRecords treeHoleReadRecords)
    {
        treeHoleReadRecords.setCreateTime(DateUtils.getNowDate());
        return treeHoleReadRecordsMapper.insertTreeHoleReadRecords(treeHoleReadRecords);
    }

    /**
     * 修改树洞内容已阅记录
     * 
     * @param treeHoleReadRecords 树洞内容已阅记录
     * @return 结果
     */
    @Override
    public int updateTreeHoleReadRecords(TreeHoleReadRecords treeHoleReadRecords)
    {
        treeHoleReadRecords.setUpdateTime(DateUtils.getNowDate());
        return treeHoleReadRecordsMapper.updateTreeHoleReadRecords(treeHoleReadRecords);
    }


    /**
     * 批量删除树洞内容已阅记录
     * 
     * @param recordIds 需要删除的树洞内容已阅记录主键
     * @return 结果
     */
    @Override
    public int deleteTreeHoleReadRecordsByRecordIds(Long[] recordIds)
    {
        return treeHoleReadRecordsMapper.deleteTreeHoleReadRecordsByRecordIds(recordIds);
    }

    /**
     * 删除树洞内容已阅记录信息
     * 
     * @param recordId 树洞内容已阅记录主键
     * @return 结果
     */
    @Override
    public int deleteTreeHoleReadRecordsByRecordId(Long recordId)
    {
        return treeHoleReadRecordsMapper.deleteTreeHoleReadRecordsByRecordId(recordId);
    }
    
    /**
     * 检查用户是否已阅读指定树洞内容
     * 
     * @param userId 用户ID
     * @param entryId 树洞内容ID
     * @return 是否已阅读
     */
    @Override
    public boolean checkUserHasRead(Long userId, Long entryId) {
        TreeHoleReadRecords query = new TreeHoleReadRecords();
        query.setUserId(userId);
        query.setEntryId(entryId);
        List<TreeHoleReadRecords> records = treeHoleReadRecordsMapper.selectTreeHoleReadRecordsList(query);
        return records != null && !records.isEmpty();
    }
    
    /**
     * 根据用户ID和树洞条目ID删除已阅记录
     * 
     * @param userId 用户ID
     * @param entryId 树洞条目ID
     * @return 结果
     */
    @Override
    public int deleteTreeHoleReadRecordsByUserIdAndEntryId(Long userId, Long entryId) {
        return treeHoleReadRecordsMapper.deleteTreeHoleReadRecordsByUserIdAndEntryId(userId, entryId);
    }
}
